<template>
  <div class="login">
    <div class="header">
      <router-link tag="div" to="/home" class="left">
        <img src="../assets/img/fanhui.png" alt="" />
        返回
      </router-link>
      <div class="mid">
        <h3>登录</h3>
      </div>
    </div>

    <div class="main">
      <div class="box">
        <div class="item">
          <img src="../assets/img/shoujihaoma.png" alt="" />
          <input type="text" placeholder="手机号" v-model="phone" />
        </div>
        <div class="item">
          <img src="../assets/img/mima.png" alt="" />
          <input type="password" placeholder="密码" v-model="password" />
        </div>
        <div class="itemz" @click="submit">
          <p>登录</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      phone: "",
      password: "",
      going: false,
    };
  },
  methods: {
    submit() {
      let reg =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      let pass = /^[a-zA-Z0-9]\w{8,17}$/;

      if (!reg.test(this.phone) || !pass.test(this.password)) {
        this.$toast("请输入正确手机号码与密码");
        return;
      } else {
        window.localStorage.setItem("token", 12345678);
        this.going = true;
        this.$toast("登录成功");
        this.$router.push("/my");
        return;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  background: #f4f4f4;
  height: 667px;
  .header {
    height: 84px;
    display: flex;
    background: #4eabe8;
    padding: 0 19px;
    padding-top: 19px;
    box-sizing: border-box;
    align-items: flex-start;
    .left {
      color: #fff;
      img {
        width: 16px;
        height: 16px;
        background-size: 100%;
      }
    }
    .mid {
      h3 {
        color: #fff;
        line-height: 22px;
        margin-right: 30px;
      }
      flex: 1;
      text-align: center;
    }
  }
  .main {
    margin: 0 20px;
    background: #fff;
    border-radius: 5px;
    .box {
      box-sizing: border-box;
      padding: 26px 20px 20px 20px;
      margin-top: -20px;

      .item {
        margin-bottom: 12px;
        display: flex;
        align-items: center;
        img {
          width: 16px;
          height: 17px;
          background-size: 100%;
          margin-right: 10px;
        }
        input {
          height: 45px;
          line-height: 45px;
          flex: 1;
          outline: none;
          border: none;
          background: #e8f0fe;
        }
      }
      .itemz {
        margin-top: 36px;
        height: 42px;
        line-height: 42px;
        background: #4eabe8;
        p {
          text-align: center;
        }
      }
    }
  }
}
</style>
